﻿using System.Collections.Generic;

namespace KxParser.Lexer
{
	/// <summary>
	/// This class represents string of one or more characters which represents some recognized rule
	/// </summary>
	/// <see cref="http://en.wikipedia.org/wiki/Token_%28parser%29#Token"/>
    public class TokenEx
    {
		/// <summary>
		/// MultiContent support - for more than one token with same content. System will not create new token, but add Name to existing token
		/// </summary>
		public List<string> Names { get; set; }

        /// <summary>
        /// Token content
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// Is token ignored
        /// </summary>
        public bool IsIgnored { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public bool IsError { get; set; }

        public int LineNumber { get; set; }

        /// <summary>
        /// Tokens start index (in line)
        /// </summary>
        public int StartIndex { get; set; }

        

        /// <summary>
        /// Tokens end index (in line)
        /// </summary>
        public int EndIndex { get; set; }

        public int TotalIndex { get; set; }

        public string Position{get { return string.Format("{0}:{1}-{2}", LineNumber + 1, StartIndex + 1, EndIndex + 1); }}

	    public string FullName
	    {
	        get
	        {
	            string ss = string.Empty;
	            foreach (string name in Names)
	            {
                    if(!string.IsNullOrEmpty(ss))
                        ss += KxParserGlobal.TokenNameSeparator;
	                ss += name;
	            }
	            return ss;
	        }
	    }

        public TokenEx()
        {
            Names = new List<string>();
        }

        public override string ToString()
        {
            return string.Format("{0}='{1}',[{2}-{3}] {4}", FullName , Content, StartIndex, EndIndex, (IsIgnored) ? "*" : "");
        }
    }
}
